<?php

namespace App\Http\Controllers\Admin\Score\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ScoreApi extends Controller
{
    public function update(Request $request)
    {
        $this->validate($request, [

            'score' => 'numeric|min:0|max:9999999.99',
        ], [
           'score.numeric' => '请填写数字',
           'score.min' => '请填写大于等于0的数字',
           'score.max' => '请填写小于等于9999999.99的数字',
           
        ]);

        $score = $request->input('score');

        $id = \DB::table('score')->value('id');
        // dd($id);

        if($id) {
            $res = \DB::table('score')->where('id', $id)->update(['relation' => $score]);
            // dd($res);
        } else {
            $res = \DB::table('score')->insert(['relation' => $score]);
            // dd($res);
        }

        if ($res) {
            return back()->with('msg', '修改成功');
        } else {
            return back()->with('msg', '修改失败');
        }

    }
}
